package cn.com.hongfu.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.com.hongfu.model.Rule;
import cn.com.hongfu.service.RuleService;
@Controller
@RequestMapping("/rule")
public class RuleController {
	@Autowired
	public RuleService ruleService ;
	/**
	 * 返回规则列表视图
	 * @return
	 */
	@RequestMapping("/ruleList")
	public String ruleList(ModelMap modelMap){
		List<Rule> rules = ruleService.getAllRule();
		modelMap.addAttribute("rules", rules);
		return "/rule/ruleList";
	}
	/**
	 * 返回新增规则视图
	 * @return
	 */
	@RequestMapping("/ruleAddUI")
	public String ruleAddUI(ModelMap modelMap){
		return "/rule/ruleAdd";
	}
	/**
	 * 处理新增规则
	 * @return 规则列表视图
	 */
	@RequestMapping("/ruleAdd")
	public String ruleAdd(ModelMap modelMap,HttpServletRequest request){
		Rule rule = new Rule();
		String name  = request.getParameter("name");
		String content  = request.getParameter("content");
		String explain  = request.getParameter("explain");
		rule.setName(name);
		rule.setContent(content);
		rule.setExplain(explain);
		ruleService.saveRule(rule);
		return "redirect:/rule/ruleList.html";
	}
}
